Total Complexity | 2 |
Total Lines | 20 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import { Strategy } from 'passport-local'; |
||
7 | |||
8 | @Injectable() |
||
9 | export class LocalStrategy extends PassportStrategy(Strategy, 'local') { |
||
10 | constructor( |
||
11 | @Inject('IQueryBus') |
||
12 | private readonly queryBus: IQueryBus |
||
13 | ) { |
||
14 | super({ |
||
15 | usernameField: 'email' |
||
16 | }); |
||
17 | } |
||
18 | |||
19 | public async validate( |
||
20 | email: string, |
||
21 | password: string |
||
22 | ): Promise<AuthenticatedView> { |
||
23 | try { |
||
24 | return await this.queryBus.execute(new LoginQuery(email, password)); |
||
25 | } catch (err) { |
||
26 | throw new UnauthorizedException('login-error-failed'); |
||
27 | } |
||
30 |